<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!--百度地图-->
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ECm5Y1jUTQmbHfQudG33S2HhWzAEW5M7"></script>
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>


    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

    <style>
        .mapList{
            width: 100%;
            height: 600px;
        }
        /*百度地图相关*/
    </style>


</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>首页<small>公司分布图</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>公司分布图</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <el-tabs type="border-card" @tab-click="refresh">

                <!--地图 分布图-->
                <el-tab-pane label="分布图">
                    <iframe src="Address_API.html" width="100%" height="580px" frameborder="0"></iframe>
                </el-tab-pane>

                <!--店铺详细信息-->
                <el-tab-pane label="详细信息">
                    <div class="mapList">

                        <div class="box">
                            <div class="filter-container">
                                <el-input placeholder="公司地址" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                                <el-button @click="findPageByString()" class="dalfBut">查询</el-button>
                                <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                            </div>

                            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>

                                <el-table-column type="index" align="center" label="序号"></el-table-column>
                                <el-table-column prop="position" label="公司地址" align="center"></el-table-column>
                                <el-table-column prop="longitude" label="经度" align="center"></el-table-column>
                                <el-table-column prop="latitude" label="纬度" align="center"></el-table-column>

                                <el-table-column label="操作" align="center">
                                    <template slot-scope="scope">
                                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                                    </template>
                                </el-table-column>

                            </el-table>
                            <!--分页条-->
                            <div class="pagination-container">
                                <el-pagination
                                        class="pagiantion"
                                        @current-change="handleCurrentChange"
                                        :current-page="pagination.currentPage"
                                        :page-size="pagination.pageSize"
                                        layout="total, prev, pager, next, jumper"
                                        :total="pagination.total">
                                </el-pagination>
                            </div>
                            <!-- 新增标签弹层 -->
                            <div class="add-form">
                                <el-dialog title="新增地址" :visible.sync="dialogFormVisible">
                                    <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">


                                        <el-row>
                                            <!--地图显示-->
                                            <iframe src="add_Address.html" width="100%" height="360px" frameborder="0"></iframe>

                                        </el-row>

                                    </el-form>
                                </el-dialog>
                            </div>

                        </div>

                    </div>
                </el-tab-pane>
            </el-tabs>
        </div>
    </div>
</div>
</body>

<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>


<script>
    var vue = new Vue({
        el: '#app',
        data:{
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:10,//每页显示的记录数
                total:0,//总记录数
                queryString:null//查询条件
            },
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            rules: {//校验规则
                longitude: [{ required: true, message: '经度为必填项', trigger: 'blur' }],
                latitude: [{ required: true, message: '纬度为必填项', trigger: 'blur' }]
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
             this.findPage();//VUE对象初始化完成后调用分页查询方法，完成分页查询
        },
        methods: {
            //刷新
            refresh(){
                //window.location.reload();
            },
            // 重置表单
            resetForm() {
                //每次点击新建按钮，弹出来的窗口都是新的，不带上次的数据
                this.formData = {}; //重置数据
            },

            // 弹出添加窗口
            handleCreate() {
                //弹出新增窗口
                this.dialogFormVisible = true;
            },
            //分页查询
            findPage() {
                //发送ajax请求，提交分页相关请求参数（页码、每页显示记录数、查询条件）
                var param = {
                    currentPage:this.pagination.currentPage,
                    pageSize:this.pagination.pageSize,
                    queryString: this.pagination.queryString
                };
                axios.post("/address/findPage.do",param).then((res)=>{
                    //解析Controller响应回的数据，为模型数据赋值
                    this.pagination.total = res.data.data.total;
                    this.dataList = res.data.data.rows;
                });
            },

            //根据条件进行分页查询
            findPageByString() {
                //alert("根据条件查询");
                //设置当前页码是第一页
                this.pagination.currentPage = 1;
                //调用分页查询的方法
                this.findPage();

            },

            //切换页码
            handleCurrentChange(currentPage) {
                //设置最新的页码
                this.pagination.currentPage = currentPage;
                //重新调用findPage方法进行分页查询
                this.findPage();
            },

            //删除权限
            handleDelete(row) {
                //使用Element框架的$conﬁrm方法，弹出提示信息
                this.$confirm('是否删除该地址?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    center: true
                }).then(() => {     //点击了确定

                    //发送axios异步请求
                    axios.post("/address/delAddressById.do?id=" + row.id).then((res)=>{
                        //判断是否删除成功
                        if (res.data.flag){
                            this.$message.success(res.data.message);
                            //重新分页查询
                            this.findPage();
                        } else{
                            //提示删除失败
                            this.$message.error(res.data.message);
                        }
                    })

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });

            },
        }
    })
</script>

</html>